#include <stdio.h>
#include <string.h>
#include <libgen.h>
#include <stdlib.h>
int  check_run(char *proname)
{
    FILE            *fp = NULL;
    char            command[150];
    char            buf[300];
    int             count = 3;
    snprintf(command, sizeof(command), "ps -ef | grep -w %s | wc -l ", proname);
    fp=popen(command, "r");
    if( !fp )
    {       
        printf("pepen errno\n");
        return -1;
    }

    if((fgets(buf, sizeof(buf), fp)) != NULL)
    {
        count = atoi(buf);
        // printf("%d\n", count);
    }
    pclose(fp);
    fp = NULL;

    if( count == 3) return 0;
    else return 1;
}
int   main(int argc, char **argv)
{
    char *prog = "ps";
    int status = check_run(prog);
    if(0 == status) printf("\n prog is running \n");
    else printf("\n no prog is running \n");
}
